<?php

namespace PAT\CommentBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * PAT\CommentBundle\Entity\Comment
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="PAT\CommentBundle\Entity\CommentRepository")
 */
class Comment
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    
    /**
     * @var string $title
     *
     * @ORM\Column(name="title", type="string", length=255)
     */
    private $title;

    /**
     * @var string $text
     *
     * @ORM\Column(name="text", type="text")
     */
    private $text;

    /**
     * @var float $rate
     *
     * @ORM\Column(name="rate", type="float")
     */
    private $rate;
    
    /**
     * @var \DateTime $pubDate
     *
     * @ORM\Column(name="pubDate", type="date")
     */
    private $pubDate;
	
	/**
     * @ORM\ManyToOne(targetEntity="PAT\ProductBundle\Entity\Product", inversedBy="comments")
     * @ORM\JoinColumn(nullable=false)
     */
    private $product;
	
	/**
     * @ORM\ManyToOne(targetEntity="PAT\UserBundle\Entity\User", inversedBy="comments")
     * @ORM\JoinColumn(nullable=false)
     */
    private $user;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set text
     *
     * @param string $text
     * @return Comment
     */
    public function setText($text)
    {
        $this->text = $text;
    
        return $this;
    }

    /**
     * Get text
     *
     * @return string 
     */
    public function getText()
    {
        return $this->text;
    }

    /**
     * Set rate
     *
     * @param float $rate
     * @return Comment
     */
    public function setRate($rate)
    {
        $this->rate = $rate;
    
        return $this;
    }

    /**
     * Get rate
     *
     * @return float 
     */
    public function getRate()
    {
        return $this->rate;
    }

    /**
     * Set product
     *
     * @param PAT\CommentBundle\Entity\Product $product
     * @return Comment
     */
    public function setProduct(\PAT\ProductBundle\Entity\Product $product)
    {
        $this->product = $product;
    
        return $this;
    }

    /**
     * Get product
     *
     * @return PAT\ProductBundle\Entity\Product 
     */
    public function getProduct()
    {
        return $this->product;
    }

    /**
     * Set user
     *
     * @param PAT\UserBundle\Entity\User $user
     * @return Comment
     */
    public function setUser(\PAT\UserBundle\Entity\User $user)
    {
        $this->user = $user;
    
        return $this;
    }

    /**
     * Get user
     *
     * @return PAT\UserBundle\Entity\User 
     */
    public function getUser()
    {
        return $this->user;
    }
    
    public function getRateHtml()
    {
       return $this->rateToHtml($this->rate);
    }
    
    public static function rateToHtml($rate)
    {
        $returnHtml="";
        
        if($rate >= 1)
        {
            for($i=0; $i<floor($rate); $i++)
            {
                $returnHtml .="<div class='full_star'></div>";
            }
        }
        
        if($rate > 0)
        {
            if($rate/ceil($rate) <> 1)
            {
                $returnHtml .="<div class='half_star'></div>";
            }
        }
        
        if($rate <=4)
        {
            for($i=5; $i>ceil($rate); $i--)
            {
                $returnHtml .="<div class='empty_star'></div>";
            }
        }
        
        return $returnHtml;                
    }

    /**
     * Set pubDate
     *
     * @param \DateTime $pubDate
     * @return Comment
     */
    public function setPubDate($pubDate)
    {
        $this->pubDate = $pubDate;
    
        return $this;
    }

    /**
     * Get pubDate
     *
     * @return \DateTime 
     */
    public function getPubDate()
    {
        return $this->pubDate;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Comment
     */
    public function setTitle($title)
    {
        $this->title = $title;
    
        return $this;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }
}